package com.jinzhi.jzweb.controller;


import java.util.*;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.common.annotation.Log;
import com.jinzhi.common.base.BaseController;
import com.jinzhi.jzweb.domain.JazGroupSpecsDO;
import com.jinzhi.jzweb.service.JazGroupSpecsService;
import com.jinzhi.common.utils.Result;

/**
 * 
 * <pre>
 * 商品规格表
 * </pre>
 * <small> 2024-05-11 13:54:23 | Long</small>
 */
@RestController
@RequestMapping("/jzweb/jazGroupSpecs")
public class JazGroupSpecsController extends BaseController {
	@Autowired
	private JazGroupSpecsService jazGroupSpecsService;
	
	@GetMapping()
	@RequiresPermissions("jzweb:jazGroupSpecs:jazGroupSpecs")
	String JazGroupSpecs(){
	    return "jzweb/jazGroupSpecs/jazGroupSpecs";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("jzweb:jazGroupSpecs:jazGroupSpecs")
	public Result<Page<JazGroupSpecsDO>> list(JazGroupSpecsDO jazGroupSpecsDTO){
		// 查询列表数据
		Page<JazGroupSpecsDO> page = jazGroupSpecsService.selectPage(getPage(JazGroupSpecsDO.class),
					jazGroupSpecsService.convertToEntityWrapper().orderBy("id", false));
		List list = new ArrayList();
		for (int i = 0; i < page.getRecords().size(); i++) {
				JazGroupSpecsDO obj = (JazGroupSpecsDO) page.getRecords().get(i);
			list.add(obj);
		}
		page.setRecords(list);
        return Result.ok(page);
	}
	
	@GetMapping("/add")
	@RequiresPermissions("jzweb:jazGroupSpecs:add")
	String add(){
	    return "jzweb/jazGroupSpecs/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("jzweb:jazGroupSpecs:edit")
	String edit(@PathVariable("id") Long id,Model model){
		JazGroupSpecsDO jazGroupSpecs = jazGroupSpecsService.selectById(id);
		model.addAttribute("jazGroupSpecs", jazGroupSpecs);
	    return "jzweb/jazGroupSpecs/edit";
	}
	
	@Log(value = "添加商品规格",sysModule = 6,operationType = 1)
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("jzweb:jazGroupSpecs:add")
	public Result<String> save( JazGroupSpecsDO jazGroupSpecs){
		jazGroupSpecsService.insert(jazGroupSpecs);
        return Result.ok();
	}
	
	@Log(value = "修改商品规格",sysModule = 6,operationType = 3)
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("jzweb:jazGroupSpecs:edit")
	public Result<String>  update( JazGroupSpecsDO jazGroupSpecs){
		boolean update = jazGroupSpecsService.updateById(jazGroupSpecs);
		return update ? Result.ok() : Result.fail();
	}
	
	@Log(value = "删除商品规格",sysModule = 6,operationType = 2)
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("jzweb:jazGroupSpecs:remove")
	public Result<String>  remove( Long id){
		jazGroupSpecsService.deleteById(id);
        return Result.ok();
	}

	@Log(value = "批量删除商品规格",sysModule = 6,operationType = 2)
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("jzweb:jazGroupSpecs:batchRemove")
	public Result<String>  remove(@RequestParam("ids[]") Long[] ids){
		jazGroupSpecsService.deleteBatchIds(Arrays.asList(ids));
		return Result.ok();
	}
	
}
